package cn.alex.springaidemo;

import cn.alex.springaidemo.openAi.function.WeatherFunctionService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackWrapper;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 聊天客户端配置
 *
 * @author Alex
 * @date 2024/9/19 23:43
 */
@Configuration
public class AiConfig {

    /**
     * 设置人设
     */
    @Bean
    public ChatClient chatClient(ChatClient.Builder builder) {
        return builder.defaultSystem("你是AI小助手，你的名字叫智联AI").build();
    }


    /**
     * 自定义函数
     */
    @Bean
    public FunctionCallback weatherFunctionInfo() {
        return FunctionCallbackWrapper.builder(new WeatherFunctionService())
                .withName("weatherFunctionService")
                .withDescription("天气服务")
                .build();
    }

    /**
     * 创建矢量存储
     */
    @Bean
    public VectorStore createVectorStore(EmbeddingModel embeddingModel) {
        return new SimpleVectorStore(embeddingModel);
    }
}
